#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int n = 0;
	scanf("%d", &n);
	while (n--)
	{
		long a, b;
		scanf("%d %d", &a, &b);
		long max=0;
		long r = a;
		long m, n;
		m = b;
		n = a;
		
			while (r = m % n)
			{
				m = n;
				n = r;
			}
			n = b / n;
			if (b % a == 0)
				max = n * n * a;
			else
				max = n * a;
		printf("%ld\n", max);
	}
}

